<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>标签管理</title>
  {include file="common/_require"}

  <script>
    var currentHeaderNavItem = 'Post-{$Request.param.type|default="1"}';
    var currentLeftNavItem = 'tag-{$Request.param.type|default="1"}';
  </script>
</head>

<body class="layui-layout-body">

  <div class="layui-layout layui-layout-admin">
    {include file="common/_header"}

    {include file="common/left_post"}

    <div class="layui-body">

      <div style="padding:15px">
        <div class="main-header">
          <span class="layui-breadcrumb">
            <a>首页</a>
            <a><cite>标签管理</cite></a>
          </span>
        </div>
        <div class="main-container">
          <div>
            <div class="layui-btn create">新增</div>
          </div>
          <div>
            <table class="layui-table">

              <thead>
                <tr>
                  <th>ID</th>
                  <th>名称</th>
                  <th>操作</th>
                </tr>
              </thead>
              <tbody>

                {volist name="list" id="vo"}
                <tr class="item" data-id="{$vo.id}">
                  <td>{$vo.id}</td>
                  <td> {:str_repeat('|--',$vo.level)} <span class="tag-name">{$vo.title}</span></td>
                  <td>
                    <div class="layui-btn-container">
                      <div class="layui-btn layui-btn-sm edit" data-href="{:url('update',['id'=>$vo.id,'type'=>$Request.param.type])}">编辑</div>
                      <div class="layui-btn layui-btn-sm delete">删除</div>
                    </div>
                  </td>

                </tr>
                {/volist}

              </tbody>
            </table>
            <div>
              {$list|raw}
            </div>
          </div>
        </div>
      </div>
    </div>


    {include file="common/_footer"}
  </div>

  <script>


    $('.delete').click(function () {
      var item = this;
      layer.confirm('确定要删除吗？', function () {
        $.get('{:url("delete")}', {
          id: $(item).parents('.item').data('id')
          
        }, function (result) {
          layer.msg('删除成功');

          $(item).parents('.item').remove();
        })
      })
    })

    $('.create').click(function () {
      layer.prompt({
        title: '请输入标签,空格分隔可添加多个'
      }, function (value, index) {
        $.post('{:url("save")}', {
          tags: value,
          type:'{$Request.param.type}'
        }, function (result) {
          layer.msg('添加成功')
          setTimeout(() => {
            location.reload()
          }, 1200);
        })
      })
    })

    $('.edit').click(function(){
      var self = this;

      layer.prompt({
        title:'请输入标签,空格无效',
        value:$(self).parents('.item').find('.tag-name').text()
      },function(value,index){
        $.post($(self).data('href'),{
          title:value
        },function(result){
          layer.msg('修改成功');

          $(self).parents('.item').find('.tag-name').text(value)
          layer.close(index)
        })
      })

    })


  </script>
</body>

</html>